//
//  DATAsyncPostAFNBlock.m
//  AFNBlockDemo
//
//  Created by dllo on 15/10/12.
//  Copyright (c) 2015年 ShangRJ. All rights reserved.
//

#import "DATAsyncPostAFNBlock.h"

@implementation DATAsyncPostAFNBlock

+ (void)PostAFNURLWithString:(NSString *)url Body:(NSDictionary *)body Cookie:(NSString *)cookie resultBlock:(PostAFNBlockResult)resultBlcok errorBlock:(PostAFNBlockError)errorBlock{
    
//    AFHTTPRequestOperationManager *netManager = [AFHTTPRequestOperationManager manager];
//    
//    //抓到的接口如果有Cookie并且没有Cookie无法正常请求数据的话需要写这句
//    //要是不用Cookie的话可以把这句删掉,函数也可以不要这个参数
//    [netManager.requestSerializer setValue:cookie forHTTPHeaderField:@"Cookie"];
//    
//    netManager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",@"application/x-javascript",nil];
//    [netManager POST:url parameters:body success:^(AFHTTPRequestOperation *operation, id responseObject) {
//        resultBlcok(responseObject);
//        
//    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//        
//        errorBlock(error);
//    }];

    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    //AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] init];
    manager.requestSerializer = [[AFHTTPRequestSerializer alloc] init];
    [manager.requestSerializer setValue:cookie forHTTPHeaderField:@"Cookie"];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",@"application/x-javascript",nil];
    [manager POST:url parameters:body success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        
        resultBlcok(responseObject);
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        
        errorBlock(error);
    }];
}


@end
